
function ShoppingCart(){
    this.goodsInfo=JSON.parse(localStorage.getItem("goodsInfo"))||{};
}
ShoppingCart.addProduct=function(product){
    var item={"classification":product.classification,"itemName":product.itemName,"price":product.price,"unit":product.unit,
        "count":1, "promotionCount":0,"savePrice":0,"costPrice":product.price,"actuallyPaid":product.price};
    return  item
};
ShoppingCart.computeActuallyPaid=function(itemInfo){
    var  actuallyPaid=itemInfo.price*(itemInfo.count-itemInfo.promotionCount);
    itemInfo.actuallyPaid=actuallyPaid;
    return  itemInfo
};
ShoppingCart.prototype.computeSumActuallyPaidPrice=function(){
    var sumActuallyPaid=0;
    for(var key in this.goodsInfo.cartList){
        sumActuallyPaid+=parseFloat(this.goodsInfo.cartList[key].actuallyPaid||0);
    }
    return  sumActuallyPaid
};
ShoppingCart.prototype.computeSumSaveParice=function(){
     var   sumSavePrice=0;
    for(var key in  this.goodsInfo.cartList){
        sumSavePrice+=parseFloat( this.goodsInfo.cartList[key].savePrice||0);
    }
    return sumSavePrice.toFixed(2);
}
ShoppingCart.prototype.computeSumCount=function(){
    var sumCount=0;
    for(var key in  this.goodsInfo.cartList){
        sumCount+=( this.goodsInfo.cartList[key].count||0);
    }
    return sumCount;
};
ShoppingCart.prototype.computeSumPrice=function(){
    var sumPrice=0;
    for(var key in  this.goodsInfo.cartList){
        sumPrice+=parseFloat( this.goodsInfo.cartList[key].costPrice||0);
    }
    return sumPrice.toFixed(2)
};


